import numpy as np
x1 = np.arange(1,11,2)        #从1开始，每隔2生成一个元素，[1,3,5,7,9]
x2 = np.linspace(1,9,5)       #1-9平分成5等分(包括结束值) , [1,3,5,7,9]
print(x1)
print(x2)

#计算单个数组平均值
print(np.mean(x1))

x3=np.array([[1,2,3],[5,6,9]])
print(np.mean(x3))                           #默认计算所有元素的平均值,(1+2+3+5+6+9)/6
print(np.mean(x3,axis=0))                    #axis=0,代表压缩行,即计算结果[(1+5)/2,(2+6)/2,(3+9)/2];axis=1，代表压缩列，计算结果[(1+2+3)/3,(5+6+9)/3]
print(np.mean(x3,axis=1))

#数组之间加法
print("x1,x2 add value: ",np.add(x1,x2))
print("x1,x2 subtract value: ",np.subtract(x1, x2))
print("x1,x2 multiply value: ",np.multiply(x1, x2))
print("x1,x2 divide value: ",np.divide(x1, x2))
print("x1,x2 power value: ",np.power(x1, x2))
print("x1,x2 remainder value: ",np.remainder(x1, x2))      #  equal    np.mod(x1,x2)

x4=np.array([[1,8,3],[4,5,6]])
print("array x4 min value: ",np.amin(x4))
print("array x4 min value: ",np.amin(x4,axis=0))
print("array x4 max value: ",np.amax(x4))

x5=np.array([[1,8,3],[4,5,6],[20,10,50]])   
print("array x4 max and min subtract: ",np.ptp(x5))       #统计最大值与最小值之差  ，50-1  
print("one axis max and min subtract: ",np.ptp(x5,0))     #压缩行axis可以省略 -> [1,4,10],[8,5,20],[3,6,50] ->[10-1,20-5,50-3]

print("x4 mid num: ",np.percentile(x4,50))                 #  percentile求（从小到大）前第百分之几的数值，[1,3,4,5,6,8],50%就是求中位数(总数量为偶数就是两个中间相加除以2),即等于（4+5）/2
print("x5 mid num: ",np.percentile(x5,50))                 # [1,3,4,5,6,8,10,20,50]  即6
print("x4 one axis mid num: ",np.percentile(x4,50,axis=0))          #axis同理 ，压缩行求中位数
print("x4 max num Via percentile: ",np.percentile(x4,100))          #q=100，代表最大值
print("x4 min num Via percentile: ",np.percentile(x4,0))            #q=0,最小值

print("x4 min num: ",np.median(x4))                                 # 中位数
print("x5 min num: ",np.median(x5))

print("x4 average: ",np.average(x4))                                #加权平均值,默认是所有数字权重一样
print("x4 average: ",np.average(x4,weights=[[2,3,2],[8,1,2]]))      #(2*1+3*8+2*3+8*4+1*5+2*6)/(2+3+2+8+1+2)=4.5

print("x4 方差: ",np.var(x4))
print("x4 标准差: ",np.std(x4))

print("sort x4: ",np.sort(x5,axis=1))           #0表示对列排序，1表示对行排序
print("sort x4: ",np.sort(x5,axis=None))           # [ 1  3  4  5  6  8 10 20 50] 